﻿using System;
using System.Collections.Generic;

namespace SBPweb.Talk.Client.Library
{

    public class ContactsManager : ClientManagerBase
    {

        #region Protected fields

        protected agsXMPP.Xmpp.Roster.Roster roster;
        protected IEnumerable<agsXMPP.Xmpp.Roster.RosterItem> rosterItems;

        #endregion

        #region Constructor logic

        internal ContactsManager(ChatClient parent)
            : base(parent)
        {
            roster = new agsXMPP.Xmpp.Roster.Roster();
            InitializeHandlers();
        }

        ~ContactsManager()
        {
            FinalizeHandlers();
        }

        #endregion

        #region Property accessors

        protected agsXMPP.Xmpp.Client.XmppClient client
        {
            get
            {
                return Parent.Connection.XmppClient;
            }
        }

        #endregion

        #region Methods

        public override void InitializeHandlers()
        {
            client.OnRosterStart += new EventHandler<agsXMPP.EventArgs>(XmppClient_OnRosterStart);
            client.OnRosterEnd += new EventHandler<agsXMPP.EventArgs>(XmppClient_OnRosterEnd);
            client.OnRosterItem += new EventHandler<agsXMPP.Xmpp.Roster.RosterEventArgs>(XmppClient_OnRosterItem);
        }

        public override void FinalizeHandlers()
        {
            client.OnRosterStart -= new EventHandler<agsXMPP.EventArgs>(XmppClient_OnRosterStart);
            client.OnRosterEnd -= new EventHandler<agsXMPP.EventArgs>(XmppClient_OnRosterEnd);
            client.OnRosterItem -= new EventHandler<agsXMPP.Xmpp.Roster.RosterEventArgs>(XmppClient_OnRosterItem);
        }

        public void Refresh()
        {
            rosterItems = roster.GetRoster();
        }

        #endregion

        #region Event handlers

        private void XmppClient_OnRosterStart(object sender, agsXMPP.EventArgs e)
        {
            throw new NotImplementedException();
        }

        private void XmppClient_OnRosterEnd(object sender, agsXMPP.EventArgs e)
        {
            throw new NotImplementedException();
        }

        private void XmppClient_OnRosterItem(object sender, agsXMPP.Xmpp.Roster.RosterEventArgs e)
        {
            throw new NotImplementedException();
        }

        #endregion

    }

}